#include "IPlugin.h"
#include "ILogger.h"
#include "IDevice.h"

class TestDevImp : public IPlugin
{
public:
    void onLoad(INode *node)
    {
        LogE("TestDevImp start");

        IDevice *input = Bean<IDevice>("input").pointer();
        IDevice *output = Bean<IDevice>("output").pointer();
        IBuffer *buffer = input->get();
        std::string content;
        output->start();
        while (buffer->copacity() == buffer->size())
        {
            content.push_back(*(char *)buffer->content());
            if ('\n' == *(char *)buffer->content())
            {
                LogI("get one line: buffer:%s size:%d", content.c_str(), content.size());
                content = "";
            }
            if ('q' == *(char *)buffer->content())
                break;
            buffer = input->get();

            output->put(buffer);
        }
        output->stop();
    }
};

REG_PLUGIN(TestDevImp)